const { checktenants, registers, isRegisters } = require('../dao/tenantsDao');

//从租赁订单中查看单个租客信息 冰
module.exports.checktenants = async function (val) {
    const data = await checktenants(val)
    return data
}

//更改租客信用值  
module.exports.modifyCredits = async function (val) {
    console.log('信用值第二层---------------', val);

    if (val.evaluateStar == 5) {
        val.tenantsCredits = val.tenantsCredits * 1 + 3
    } else if (val.evaluateStar == 4) {
        val.tenantsCredits = val.tenantsCredits * 1 + 2
    } else if (val.evaluateStar == 3) {
        val.tenantsCredits = val.tenantsCredits * 1 + 1
    } else if (val.evaluateStar == 2) {
        val.tenantsCredits = val.tenantsCredits * 1 - 2
    } else if (val.evaluateStar == 1) {
        val.tenantsCredits = val.tenantsCredits * 1 - 3
    }

    const data = await modifyCredits(val)
    if (data.nModified) {
        return {
            message: '修改租客信用值成功',
            status: 1,
        }
    } else {
        return {
            message: '修改租客信用值失败',
            status: 0,
        }
    }
}

/*****************练超*******************/
//租客注册
module.exports.registers = async function (val) {
    const data = await registers(val)
    if (data._id) {
        return {
            message: '注册成功',
            status: 1
        }
    }
    return {
        message: '注册失败',
        status: 0
    }
}

//租客验证账号是否存在
module.exports.isRegisters = async isData => {
    const data = await isRegisters(isData);
    if (data.length > 0) {
        return {
            message: '账号已存在，不合法',
            status: 0,
        }
    }
    return {
        message: "账号合法",
        status: 1
    }
}